
import { get_All_role, get_company, Add_role, Delete_role, Update_role } from '@/api/role.js'
const state = {
  Allroles: [],
  Company: {}
}
const mutations = {
  setAllrole(state, data) {
    state.Allroles = data
  },
  setCompany(state, data) {
    state.Company = data
  }
}
const actions = {
  async get_All_role(store, pageConfig = { page: 1, pagesize: 5 }) {
    const res = await get_All_role(pageConfig)
    store.commit('setAllrole', res)
  },
  async get_company(store, id) {
    const res = await get_company(id)
    store.commit('setCompany', res)
  },
  async Add_role(store, data) {
    await Add_role(data)
    store.dispatch('get_All_role')
  },
  async Delete_role(store, id) {
    await Delete_role(id)
    store.dispatch('get_All_role')
  },
  async Update_role(store, data) {
    await Update_role(data.id, data)
    store.dispatch('get_All_role')
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}

